package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class AttendanceDS extends AbstractDS {

    private static AttendanceDS instance;

    private AttendanceDS() {
        super(Service.ATTENDANCE_DETAIL);

        DataSourceIntegerField id = new DataSourceIntegerField(Parameter.ID);
        id.setHidden(true);
        id.setPrimaryKey(true);

        DataSourceTextField trainee = new DataSourceTextField(Parameter.TRAINEE);
        trainee.setValueXPath(combineXPath(Parameter.TRAINEE, Parameter.ID));
        trainee.setTypeAsDataSource(TraineeDS.getInstance());

        DataSourceTextField status = new DataSourceTextField(Parameter.STATUS);
        status.setValueXPath(combineXPath(Parameter.STATUS, Parameter.ID));
        status.setTypeAsDataSource(AttendanceStatusDS.getInstance());

        DataSourceTextField attendanceReport = new DataSourceTextField();
        attendanceReport.setValueXPath(combineXPath(Parameter.ATTENDANCE_LIST, Parameter.ID));
        attendanceReport.setTypeAsDataSource(AttendanceReportDS.getInstance());

        DataSourceTextField commentField = new DataSourceTextField(Parameter.COMMENT);

        DataSourceTextField lastNameField = new DataSourceTextField(Parameter.LAST_NAME);
        lastNameField.setValueXPath(combineXPath(Parameter.TRAINEE, Parameter.LAST_NAME));
        lastNameField.setCanEdit(false);

        DataSourceTextField firstNameField = new DataSourceTextField(Parameter.FIRST_NAME);
        firstNameField.setValueXPath(combineXPath(Parameter.TRAINEE, Parameter.FIRST_NAME));
        firstNameField.setCanEdit(false);

        setFields(id, trainee, attendanceReport, status, commentField, lastNameField, firstNameField);
    }

    public static AttendanceDS getInstance() {
        if (instance == null) {
            instance = new AttendanceDS();
        }

        return instance;
    }
}
